<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Tie::File - Access the lines of a disk file via a Perl array - Perldoc Browser</title>
    <link rel="search" href="https://perldoc.perl.org/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser">
    <link rel="canonical" href="https://perldoc.perl.org/Tie::File">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" />
    <style>
      body {
        background: #f4f4f5;
        color: #020202;
      }
      .navbar-dark {
        background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%);
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0);
        background-repeat: repeat-x;
      }
      .navbar-dark .navbar-nav .nav-link,
      .navbar-dark .navbar-nav .nav-link:focus { color: #fff }
      .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 }
      #wrapperlicious {
        margin: 0 auto;
        font: 0.9em 'Helvetica Neue', Helvetica, sans-serif;
        font-weight: normal;
        line-height: 1.5em;
        margin: 0;
        padding: 0;
      }
      #wrapperlicious h1 { font-size: 1.5em }
      #wrapperlicious h2 { font-size: 1.3em }
      #wrapperlicious h3 { font-size: 1.1em }
      #wrapperlicious h4 { font-size: 0.9em }
      #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3,
      #wrapperlicious h4, #wrapperlicious dt {
        color: #020202;
        margin-top: 1em;
        margin-bottom: 1em;
        position: relative;
        font-weight: bold;
      }
      #wrapperlicious a { color: inherit; text-decoration: underline }
      #wrapperlicious #toc { text-decoration: none }
      #wrapperlicious a:hover { color: #2a2a2a }
      #wrapperlicious a img { border: 0 }
      #wrapperlicious :not(pre) > code {
        color: inherit;
        background-color: rgba(0, 0, 0, 0.04);
        border-radius: 3px;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        padding: 0.3em;
      }
      #wrapperlicious dd {
        margin: 0;
        margin-left: 2em;
      }
      #wrapperlicious dt {
        color: #2a2a2a;
        font-weight: bold;
        margin-left: 0.9em;
      }
      #wrapperlicious p {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious li > p {
        margin-bottom: 0;
        margin-top: 0;
      }
      #wrapperlicious pre {
        border: 1px solid #c1c1c1;
        border-radius: 3px;
        font: 100% Consolas, Menlo, Monaco, monospace;
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious pre > code {
        display: block;
        background-color: #f6f6f6;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        line-height: 1.5em;
        text-align: left;
        white-space: pre;
        padding: 1em;
      }
      #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious ul {
        list-style-type: square;
      }
      #wrapperlicious ul ul {
        margin-bottom: 0px;
        margin-top: 0px;
      }
      #footer {
        font-size: 0.8em;
        padding-top: 0.5em;
        text-align: center;
      }
      #more {
        display: inline;
        font-size: 0.8em;
      }
      #perldocdiv {
        background-color: #fff;
        border: 1px solid #c1c1c1;
        border-bottom-left-radius: 5px;
        border-bottom-right-radius: 5px;
        margin-left: auto;
        margin-right: auto;
        padding: 3em;
        padding-top: 1em;
        max-width: 960px;
      }
      #moduleversion { float: right }
      #wrapperlicious .leading-notice {
        font-style: italic;
        padding-left: 1em;
        margin-top: 1em;
        margin-bottom: 1em;
      }
      #wrapperlicious .permalink {
        display: none;
        left: -0.75em;
        position: absolute;
        padding-right: 0.25em;
        text-decoration: none;
      }
      #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink,
      #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink,
      #wrapperlicious dt:hover .permalink {
        display: block;
      }
    </style>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-KVNWBNT5FB');
      gtag('config', 'UA-50555-3');
    </script>
  </head>
  <body>
    <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <a class="navbar-brand" href="https://perldoc.perl.org/">Perldoc Browser</a>
  <div class="collapse navbar-collapse" id="navbarNav">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./Tie::File.html#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.35.0</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-stable">
          <a class="dropdown-item" href="https://perldoc.perl.org/Tie::File">Latest</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.2/Tie::File">5.38.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.1/Tie::File">5.38.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0/Tie::File">5.38.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.3/Tie::File">5.36.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.2/Tie::File">5.36.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.1/Tie::File">5.36.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.0/Tie::File">5.36.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.3/Tie::File">5.34.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.2/Tie::File">5.34.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.1/Tie::File">5.34.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.0/Tie::File">5.34.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.1/Tie::File">5.32.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.0/Tie::File">5.32.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.3/Tie::File">5.30.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.2/Tie::File">5.30.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.1/Tie::File">5.30.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.0/Tie::File">5.30.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.3/Tie::File">5.28.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.2/Tie::File">5.28.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.1/Tie::File">5.28.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.0/Tie::File">5.28.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.3/Tie::File">5.26.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.2/Tie::File">5.26.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.1/Tie::File">5.26.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.0/Tie::File">5.26.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.4/Tie::File">5.24.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.3/Tie::File">5.24.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.2/Tie::File">5.24.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.1/Tie::File">5.24.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.0/Tie::File">5.24.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.4/Tie::File">5.22.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.3/Tie::File">5.22.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.2/Tie::File">5.22.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.1/Tie::File">5.22.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.0/Tie::File">5.22.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.3/Tie::File">5.20.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.2/Tie::File">5.20.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.1/Tie::File">5.20.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.0/Tie::File">5.20.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.4/Tie::File">5.18.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.3/Tie::File">5.18.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.2/Tie::File">5.18.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.1/Tie::File">5.18.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.0/Tie::File">5.18.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.3/Tie::File">5.16.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.2/Tie::File">5.16.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.1/Tie::File">5.16.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.0/Tie::File">5.16.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.4/Tie::File">5.14.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.3/Tie::File">5.14.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.2/Tie::File">5.14.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.1/Tie::File">5.14.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.0/Tie::File">5.14.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.5/Tie::File">5.12.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.4/Tie::File">5.12.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.3/Tie::File">5.12.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.2/Tie::File">5.12.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.1/Tie::File">5.12.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.0/Tie::File">5.12.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.1/Tie::File">5.10.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.0/Tie::File">5.10.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.9/Tie::File">5.8.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.8/Tie::File">5.8.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.7/Tie::File">5.8.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.6/Tie::File">5.8.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.5/Tie::File">5.8.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.4/Tie::File">5.8.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.3/Tie::File">5.8.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.2/Tie::File">5.8.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.1/Tie::File">5.8.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.0/Tie::File">5.8.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.2/Tie::File">5.6.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.1/Tie::File">5.6.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.0/Tie::File">5.6.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_04/Tie::File">5.005_04</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_03/Tie::File">5.005_03</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_02/Tie::File">5.005_02</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_01/Tie::File">5.005_01</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005/Tie::File">5.005</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./Tie::File.html#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-dev">
          <a class="dropdown-item" href="https://perldoc.perl.org/blead/Tie::File">blead</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.6/Tie::File">5.39.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.5/Tie::File">5.39.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.4/Tie::File">5.39.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.3/Tie::File">5.39.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.2/Tie::File">5.39.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.1/Tie::File">5.39.1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC2/Tie::File">5.38.0-RC2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC1/Tie::File">5.38.0-RC1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.11/Tie::File">5.37.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.10/Tie::File">5.37.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.9/Tie::File">5.37.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.8/Tie::File">5.37.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.7/Tie::File">5.37.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.6/Tie::File">5.37.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.5/Tie::File">5.37.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.4/Tie::File">5.37.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.3/Tie::File">5.37.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.2/Tie::File">5.37.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.1/Tie::File">5.37.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.0/Tie::File">5.37.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.11/Tie::File">5.35.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.10/Tie::File">5.35.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.9/Tie::File">5.35.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.8/Tie::File">5.35.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.7/Tie::File">5.35.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.6/Tie::File">5.35.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.5/Tie::File">5.35.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.4/Tie::File">5.35.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.3/Tie::File">5.35.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.2/Tie::File">5.35.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.1/Tie::File">5.35.1</a>
          <a class="dropdown-item active" href="./Tie::File.html">5.35.0</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./Tie::File.html#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-nav">
          <a class="dropdown-item" href="perl.html">Perl</a>
          <a class="dropdown-item" href="perlintro.html">Intro</a>
          <a class="dropdown-item" href="perl.html#Tutorials">Tutorials</a>
          <a class="dropdown-item" href="perlfaq.html">FAQs</a>
          <a class="dropdown-item" href="perl.html#Reference-Manual">Reference</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlop.html">Operators</a>
          <a class="dropdown-item" href="functions.html">Functions</a>
          <a class="dropdown-item" href="variables.html">Variables</a>
          <a class="dropdown-item" href="modules.html">Modules</a>
          <a class="dropdown-item" href="perlutil.html">Utilities</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlcommunity.html">Community</a>
          <a class="dropdown-item" href="perlhist.html">History</a>
        </div>
      </li>
    </ul>
    <ul class="navbar-nav">
      <script>
        function set_expand (expand) {
          var perldocdiv = document.getElementById('perldocdiv');
          var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width');
          var expanded = (width == '' || width == 'none') ? true : false;
          if (expand === null) {
            expand = !expanded;
          }
          if ((expand && !expanded) || (!expand && expanded)) {
            perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px');
            var button_classlist = document.getElementById('content-expand-button').classList;
            if (expand) {
              button_classlist.add('btn-light');
              button_classlist.remove('btn-outline-light');
            } else {
              button_classlist.add('btn-outline-light');
              button_classlist.remove('btn-light');
            }
          }
          return expand;
        }
        function toggle_expand () {
          var expand = set_expand(null);
          document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC';
        }
        function read_expand () {
          return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 });
        }
        if (document.readyState === 'loading') {
          document.addEventListener('DOMContentLoaded', function () {
            if (read_expand()) {
              set_expand(true);
            }
          });
        } else if (read_expand()) {
          set_expand(true);
        }
      </script>
      <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-2" onclick="toggle_expand()">Expand</button>
    <ul>
    <form class="form-inline" method="get" action="https://perldoc.perl.org/5.35.0/search">
      <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search">
    </form>
  </div>
</nav>

    <div id="wrapperlicious" class="container-fluid">
      <div id="perldocdiv">
        <div id="links">
          <a href="./Tie::File.html">Tie::File</a>
          <div id="more">
            (<a href="./Tie::File.txt">source</a>,
            <a href="https://metacpan.org/pod/Tie::File">CPAN</a>)
          </div>
            <div id="moduleversion">version 1.06</div>
        </div>
        <div class="leading-notice">
          You are viewing the version of this documentation from Perl 5.35.0.
            This is a development version of Perl.
        </div>
        <h1><a id="toc">CONTENTS</a></h1>
                  <ul>
              <li>
                <a class="text-decoration-none" href="./Tie::File.html#NAME">NAME</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Tie::File.html#SYNOPSIS">SYNOPSIS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Tie::File.html#DESCRIPTION">DESCRIPTION</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./Tie::File.html#recsep">recsep</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Tie::File.html#autochomp">autochomp</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Tie::File.html#mode">mode</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Tie::File.html#memory">memory</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Tie::File.html#dw_size">dw_size</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Tie::File.html#Option-Format">Option Format</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./Tie::File.html#Public-Methods">Public Methods</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./Tie::File.html#flock">flock</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Tie::File.html#autochomp1">autochomp</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Tie::File.html#defer,-flush,-discard,-and-autodefer">defer, flush, discard, and autodefer</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Tie::File.html#offset">offset</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./Tie::File.html#Tying-to-an-already-opened-filehandle">Tying to an already-opened filehandle</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Tie::File.html#Deferred-Writing">Deferred Writing</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./Tie::File.html#Autodeferring">Autodeferring</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./Tie::File.html#CONCURRENT-ACCESS-TO-FILES">CONCURRENT ACCESS TO FILES</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Tie::File.html#CAVEATS">CAVEATS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Tie::File.html#SUBCLASSING">SUBCLASSING</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Tie::File.html#WHAT-ABOUT-DB_File?">WHAT ABOUT DB_File?</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Tie::File.html#AUTHOR">AUTHOR</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Tie::File.html#LICENSE">LICENSE</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Tie::File.html#WARRANTY">WARRANTY</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Tie::File.html#THANKS">THANKS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Tie::File.html#TODO">TODO</a>
              </li>
          </ul>

      <h1 id="NAME"><a class="permalink" href="./Tie::File.html#NAME">#</a>NAME</h1>

<p>Tie::File - Access the lines of a disk file via a Perl array</p>

<h1 id="SYNOPSIS"><a class="permalink" href="./Tie::File.html#SYNOPSIS">#</a>SYNOPSIS</h1>

<pre><code>use Tie::File;

tie @array, &#39;Tie::File&#39;, filename or die ...;

$array[0] = &#39;blah&#39;;      # first line of the file is now &#39;blah&#39;
                           # (line numbering starts at 0)
print $array[42];        # display line 43 of the file

$n_recs = @array;        # how many records are in the file?
$#array -= 2;            # chop two records off the end


for (@array) {
  s/PERL/Perl/g;        # Replace PERL with Perl everywhere in the file
}

# These are just like regular push, pop, unshift, shift, and splice
# Except that they modify the file in the way you would expect

push @array, new recs...;
my $r1 = pop @array;
unshift @array, new recs...;
my $r2 = shift @array;
@old_recs = splice @array, 3, 7, new recs...;

untie @array;            # all finished</code></pre>

<h1 id="DESCRIPTION"><a class="permalink" href="./Tie::File.html#DESCRIPTION">#</a>DESCRIPTION</h1>

<p><code>Tie::File</code> represents a regular text file as a Perl array. Each element in the array corresponds to a record in the file. The first line of the file is element 0 of the array; the second line is element 1, and so on.</p>

<p>The file is <i>not</i> loaded into memory, so this will work even for gigantic files.</p>

<p>Changes to the array are reflected in the file immediately.</p>

<p>Lazy people and beginners may now stop reading the manual.</p>

<h2 id="recsep"><a class="permalink" href="./Tie::File.html#recsep">#</a><code>recsep</code></h2>

<p>What is a &#39;record&#39;? By default, the meaning is the same as for the <code>&lt;...&gt;</code> operator: It&#39;s a string terminated by <code>$/</code>, which is probably <code>&quot;\n&quot;</code>. (Minor exception: on DOS and Win32 systems, a &#39;record&#39; is a string terminated by <code>&quot;\r\n&quot;</code>.) You may change the definition of &quot;record&quot; by supplying the <code>recsep</code> option in the <code>tie</code> call:</p>

<pre><code>tie @array, &#39;Tie::File&#39;, $file, recsep =&gt; &#39;es&#39;;</code></pre>

<p>This says that records are delimited by the string <code>es</code>. If the file contained the following data:</p>

<pre><code class="plaintext">Curse these pesky flies!\n</code></pre>

<p>then the <code>@array</code> would appear to have four elements:</p>

<pre><code class="plaintext">&quot;Curse th&quot;
&quot;e p&quot;
&quot;ky fli&quot;
&quot;!\n&quot;</code></pre>

<p>An undefined value is not permitted as a record separator. Perl&#39;s special &quot;paragraph mode&quot; semantics (à la <code>$/ = &quot;&quot;</code>) are not emulated.</p>

<p>Records read from the tied array do not have the record separator string on the end; this is to allow</p>

<pre><code>$array[17] .= &quot;extra&quot;;</code></pre>

<p>to work as expected.</p>

<p>(See <a href="./Tie::File.html#autochomp">&quot;autochomp&quot;</a>, below.) Records stored into the array will have the record separator string appended before they are written to the file, if they don&#39;t have one already. For example, if the record separator string is <code>&quot;\n&quot;</code>, then the following two lines do exactly the same thing:</p>

<pre><code>$array[17] = &quot;Cherry pie&quot;;
$array[17] = &quot;Cherry pie\n&quot;;</code></pre>

<p>The result is that the contents of line 17 of the file will be replaced with &quot;Cherry pie&quot;; a newline character will separate line 17 from line 18. This means that this code will do nothing:</p>

<pre><code>chomp $array[17];</code></pre>

<p>Because the <code>chomp</code>ed value will have the separator reattached when it is written back to the file. There is no way to create a file whose trailing record separator string is missing.</p>

<p>Inserting records that <i>contain</i> the record separator string is not supported by this module. It will probably produce a reasonable result, but what this result will be may change in a future version. Use &#39;splice&#39; to insert records or to replace one record with several.</p>

<h2 id="autochomp"><a class="permalink" href="./Tie::File.html#autochomp">#</a><code>autochomp</code></h2>

<p>Normally, array elements have the record separator removed, so that if the file contains the text</p>

<pre><code class="plaintext">Gold
Frankincense
Myrrh</code></pre>

<p>the tied array will appear to contain <code>(&quot;Gold&quot;, &quot;Frankincense&quot;, &quot;Myrrh&quot;)</code>. If you set <code>autochomp</code> to a false value, the record separator will not be removed. If the file above was tied with</p>

<pre><code>tie @gifts, &quot;Tie::File&quot;, $gifts, autochomp =&gt; 0;</code></pre>

<p>then the array <code>@gifts</code> would appear to contain <code>(&quot;Gold\n&quot;, &quot;Frankincense\n&quot;, &quot;Myrrh\n&quot;)</code>, or (on Win32 systems) <code>(&quot;Gold\r\n&quot;, &quot;Frankincense\r\n&quot;, &quot;Myrrh\r\n&quot;)</code>.</p>

<h2 id="mode"><a class="permalink" href="./Tie::File.html#mode">#</a><code>mode</code></h2>

<p>Normally, the specified file will be opened for read and write access, and will be created if it does not exist. (That is, the flags <code>O_RDWR | O_CREAT</code> are supplied in the <code>open</code> call.) If you want to change this, you may supply alternative flags in the <code>mode</code> option. See <a href="Fcntl.html">Fcntl</a> for a listing of available flags. For example:</p>

<pre><code># open the file if it exists, but fail if it does not exist
use Fcntl &#39;O_RDWR&#39;;
tie @array, &#39;Tie::File&#39;, $file, mode =&gt; O_RDWR;

# create the file if it does not exist
use Fcntl &#39;O_RDWR&#39;, &#39;O_CREAT&#39;;
tie @array, &#39;Tie::File&#39;, $file, mode =&gt; O_RDWR | O_CREAT;

# open an existing file in read-only mode
use Fcntl &#39;O_RDONLY&#39;;
tie @array, &#39;Tie::File&#39;, $file, mode =&gt; O_RDONLY;</code></pre>

<p>Opening the data file in write-only or append mode is not supported.</p>

<h2 id="memory"><a class="permalink" href="./Tie::File.html#memory">#</a><code>memory</code></h2>

<p>This is an upper limit on the amount of memory that <code>Tie::File</code> will consume at any time while managing the file. This is used for two things: managing the <i>read cache</i> and managing the <i>deferred write buffer</i>.</p>

<p>Records read in from the file are cached, to avoid having to re-read them repeatedly. If you read the same record twice, the first time it will be stored in memory, and the second time it will be fetched from the <i>read cache</i>. The amount of data in the read cache will not exceed the value you specified for <code>memory</code>. If <code>Tie::File</code> wants to cache a new record, but the read cache is full, it will make room by expiring the least-recently visited records from the read cache.</p>

<p>The default memory limit is 2Mib. You can adjust the maximum read cache size by supplying the <code>memory</code> option. The argument is the desired cache size, in bytes.</p>

<pre><code># I have a lot of memory, so use a large cache to speed up access
tie @array, &#39;Tie::File&#39;, $file, memory =&gt; 20_000_000;</code></pre>

<p>Setting the memory limit to 0 will inhibit caching; records will be fetched from disk every time you examine them.</p>

<p>The <code>memory</code> value is not an absolute or exact limit on the memory used. <code>Tie::File</code> objects contains some structures besides the read cache and the deferred write buffer, whose sizes are not charged against <code>memory</code>.</p>

<p>The cache itself consumes about 310 bytes per cached record, so if your file has many short records, you may want to decrease the cache memory limit, or else the cache overhead may exceed the size of the cached data.</p>

<h2 id="dw_size"><a class="permalink" href="./Tie::File.html#dw_size">#</a><code>dw_size</code></h2>

<p>(This is an advanced feature. Skip this section on first reading.)</p>

<p>If you use deferred writing (See <a href="./Tie::File.html#Deferred-Writing">&quot;Deferred Writing&quot;</a>, below) then data you write into the array will not be written directly to the file; instead, it will be saved in the <i>deferred write buffer</i> to be written out later. Data in the deferred write buffer is also charged against the memory limit you set with the <code>memory</code> option.</p>

<p>You may set the <code>dw_size</code> option to limit the amount of data that can be saved in the deferred write buffer. This limit may not exceed the total memory limit. For example, if you set <code>dw_size</code> to 1000 and <code>memory</code> to 2500, that means that no more than 1000 bytes of deferred writes will be saved up. The space available for the read cache will vary, but it will always be at least 1500 bytes (if the deferred write buffer is full) and it could grow as large as 2500 bytes (if the deferred write buffer is empty.)</p>

<p>If you don&#39;t specify a <code>dw_size</code>, it defaults to the entire memory limit.</p>

<h2 id="Option-Format"><a class="permalink" href="./Tie::File.html#Option-Format">#</a><a id="Option"></a>Option Format</h2>

<p><code>-mode</code> is a synonym for <code>mode</code>. <code>-recsep</code> is a synonym for <code>recsep</code>. <code>-memory</code> is a synonym for <code>memory</code>. You get the idea.</p>

<h1 id="Public-Methods"><a class="permalink" href="./Tie::File.html#Public-Methods">#</a><a id="Public"></a>Public Methods</h1>

<p>The <code>tie</code> call returns an object, say <code>$o</code>. You may call</p>

<pre><code>$rec = $o-&gt;FETCH($n);
$o-&gt;STORE($n, $rec);</code></pre>

<p>to fetch or store the record at line <code>$n</code>, respectively; similarly the other tied array methods. (See <a href="perltie.html">perltie</a> for details.) You may also call the following methods on this object:</p>

<h2 id="flock"><a class="permalink" href="./Tie::File.html#flock">#</a><code>flock</code></h2>

<pre><code>$o-&gt;flock(MODE)</code></pre>

<p>will lock the tied file. <code>MODE</code> has the same meaning as the second argument to the Perl built-in <code>flock</code> function; for example <code>LOCK_SH</code> or <code>LOCK_EX | LOCK_NB</code>. (These constants are provided by the <code>use Fcntl &#39;:flock&#39;</code> declaration.)</p>

<p><code>MODE</code> is optional; the default is <code>LOCK_EX</code>.</p>

<p><code>Tie::File</code> maintains an internal table of the byte offset of each record it has seen in the file.</p>

<p>When you use <code>flock</code> to lock the file, <code>Tie::File</code> assumes that the read cache is no longer trustworthy, because another process might have modified the file since the last time it was read. Therefore, a successful call to <code>flock</code> discards the contents of the read cache and the internal record offset table.</p>

<p><code>Tie::File</code> promises that the following sequence of operations will be safe:</p>

<pre><code>my $o = tie @array, &quot;Tie::File&quot;, $filename;
$o-&gt;flock;</code></pre>

<p>In particular, <code>Tie::File</code> will <i>not</i> read or write the file during the <code>tie</code> call. (Exception: Using <code>mode =&gt; O_TRUNC</code> will, of course, erase the file during the <code>tie</code> call. If you want to do this safely, then open the file without <code>O_TRUNC</code>, lock the file, and use <code>@array = ()</code>.)</p>

<p>The best way to unlock a file is to discard the object and untie the array. It is probably unsafe to unlock the file without also untying it, because if you do, changes may remain unwritten inside the object. That is why there is no shortcut for unlocking. If you really want to unlock the file prematurely, you know what to do; if you don&#39;t know what to do, then don&#39;t do it.</p>

<p>All the usual warnings about file locking apply here. In particular, note that file locking in Perl is <b>advisory</b>, which means that holding a lock will not prevent anyone else from reading, writing, or erasing the file; it only prevents them from getting another lock at the same time. Locks are analogous to green traffic lights: If you have a green light, that does not prevent the idiot coming the other way from plowing into you sideways; it merely guarantees to you that the idiot does not also have a green light at the same time.</p>

<h2 id="autochomp1"><a class="permalink" href="./Tie::File.html#autochomp1">#</a><code>autochomp</code></h2>

<pre><code>my $old_value = $o-&gt;autochomp(0);    # disable autochomp option
my $old_value = $o-&gt;autochomp(1);    #  enable autochomp option

my $ac = $o-&gt;autochomp();   # recover current value</code></pre>

<p>See <a href="./Tie::File.html#autochomp">&quot;autochomp&quot;</a>, above.</p>

<h2 id="defer,-flush,-discard,-and-autodefer"><a class="permalink" href="./Tie::File.html#defer,-flush,-discard,-and-autodefer">#</a><a id="defer"></a><a id="defer-flush-discard-and-autodefer"></a><code>defer</code>, <code>flush</code>, <code>discard</code>, and <code>autodefer</code></h2>

<p>See <a href="./Tie::File.html#Deferred-Writing">&quot;Deferred Writing&quot;</a>, below.</p>

<h2 id="offset"><a class="permalink" href="./Tie::File.html#offset">#</a><code>offset</code></h2>

<pre><code>$off = $o-&gt;offset($n);</code></pre>

<p>This method returns the byte offset of the start of the <code>$n</code>th record in the file. If there is no such record, it returns an undefined value.</p>

<h1 id="Tying-to-an-already-opened-filehandle"><a class="permalink" href="./Tie::File.html#Tying-to-an-already-opened-filehandle">#</a><a id="Tying"></a>Tying to an already-opened filehandle</h1>

<p>If <code>$fh</code> is a filehandle, such as is returned by <code>IO::File</code> or one of the other <code>IO</code> modules, you may use:</p>

<pre><code>tie @array, &#39;Tie::File&#39;, $fh, ...;</code></pre>

<p>Similarly if you opened that handle <code>FH</code> with regular <code>open</code> or <code>sysopen</code>, you may use:</p>

<pre><code>tie @array, &#39;Tie::File&#39;, \*FH, ...;</code></pre>

<p>Handles that were opened write-only won&#39;t work. Handles that were opened read-only will work as long as you don&#39;t try to modify the array. Handles must be attached to seekable sources of data---that means no pipes or sockets. If <code>Tie::File</code> can detect that you supplied a non-seekable handle, the <code>tie</code> call will throw an exception. (On Unix systems, it can detect this.)</p>

<p>Note that Tie::File will only close any filehandles that it opened internally. If you passed it a filehandle as above, you &quot;own&quot; the filehandle, and are responsible for closing it after you have untied the @array.</p>

<p>Tie::File calls <code>binmode</code> on filehandles that it opens internally, but not on filehandles passed in by the user. For consistency, especially if using the tied files cross-platform, you may wish to call <code>binmode</code> on the filehandle prior to tying the file.</p>

<h1 id="Deferred-Writing"><a class="permalink" href="./Tie::File.html#Deferred-Writing">#</a><a id="Deferred"></a>Deferred Writing</h1>

<p>(This is an advanced feature. Skip this section on first reading.)</p>

<p>Normally, modifying a <code>Tie::File</code> array writes to the underlying file immediately. Every assignment like <code>$a[3] = ...</code> rewrites as much of the file as is necessary; typically, everything from line 3 through the end will need to be rewritten. This is the simplest and most transparent behavior. Performance even for large files is reasonably good.</p>

<p>However, under some circumstances, this behavior may be excessively slow. For example, suppose you have a million-record file, and you want to do:</p>

<pre><code>for (@FILE) {
  $_ = &quot;&gt; $_&quot;;
}</code></pre>

<p>The first time through the loop, you will rewrite the entire file, from line 0 through the end. The second time through the loop, you will rewrite the entire file from line 1 through the end. The third time through the loop, you will rewrite the entire file from line 2 to the end. And so on.</p>

<p>If the performance in such cases is unacceptable, you may defer the actual writing, and then have it done all at once. The following loop will perform much better for large files:</p>

<pre><code>(tied @a)-&gt;defer;
for (@a) {
  $_ = &quot;&gt; $_&quot;;
}
(tied @a)-&gt;flush;</code></pre>

<p>If <code>Tie::File</code>&#39;s memory limit is large enough, all the writing will done in memory. Then, when you call <code>-&gt;flush</code>, the entire file will be rewritten in a single pass.</p>

<p>(Actually, the preceding discussion is something of a fib. You don&#39;t need to enable deferred writing to get good performance for this common case, because <code>Tie::File</code> will do it for you automatically unless you specifically tell it not to. See <a href="./Tie::File.html#Autodeferring">&quot;Autodeferring&quot;</a>, below.)</p>

<p>Calling <code>-&gt;flush</code> returns the array to immediate-write mode. If you wish to discard the deferred writes, you may call <code>-&gt;discard</code> instead of <code>-&gt;flush</code>. Note that in some cases, some of the data will have been written already, and it will be too late for <code>-&gt;discard</code> to discard all the changes. Support for <code>-&gt;discard</code> may be withdrawn in a future version of <code>Tie::File</code>.</p>

<p>Deferred writes are cached in memory up to the limit specified by the <code>dw_size</code> option (see above). If the deferred-write buffer is full and you try to write still more deferred data, the buffer will be flushed. All buffered data will be written immediately, the buffer will be emptied, and the now-empty space will be used for future deferred writes.</p>

<p>If the deferred-write buffer isn&#39;t yet full, but the total size of the buffer and the read cache would exceed the <code>memory</code> limit, the oldest records will be expired from the read cache until the total size is under the limit.</p>

<p><code>push</code>, <code>pop</code>, <code>shift</code>, <code>unshift</code>, and <code>splice</code> cannot be deferred. When you perform one of these operations, any deferred data is written to the file and the operation is performed immediately. This may change in a future version.</p>

<p>If you resize the array with deferred writing enabled, the file will be resized immediately, but deferred records will not be written. This has a surprising consequence: <code>@a = (...)</code> erases the file immediately, but the writing of the actual data is deferred. This might be a bug. If it is a bug, it will be fixed in a future version.</p>

<h2 id="Autodeferring"><a class="permalink" href="./Tie::File.html#Autodeferring">#</a>Autodeferring</h2>

<p><code>Tie::File</code> tries to guess when deferred writing might be helpful, and to turn it on and off automatically.</p>

<pre><code>for (@a) {
  $_ = &quot;&gt; $_&quot;;
}</code></pre>

<p>In this example, only the first two assignments will be done immediately; after this, all the changes to the file will be deferred up to the user-specified memory limit.</p>

<p>You should usually be able to ignore this and just use the module without thinking about deferring. However, special applications may require fine control over which writes are deferred, or may require that all writes be immediate. To disable the autodeferment feature, use</p>

<pre><code>(tied @o)-&gt;autodefer(0);</code></pre>

<p>or</p>

<pre><code>tie @array, &#39;Tie::File&#39;, $file, autodefer =&gt; 0;</code></pre>

<p>Similarly, <code>-&gt;autodefer(1)</code> re-enables autodeferment, and <code>-&gt;autodefer()</code> recovers the current value of the autodefer setting.</p>

<h1 id="CONCURRENT-ACCESS-TO-FILES"><a class="permalink" href="./Tie::File.html#CONCURRENT-ACCESS-TO-FILES">#</a><a id="CONCURRENT"></a>CONCURRENT ACCESS TO FILES</h1>

<p>Caching and deferred writing are inappropriate if you want the same file to be accessed simultaneously from more than one process. Other optimizations performed internally by this module are also incompatible with concurrent access. A future version of this module will support a <code>concurrent =&gt; 1</code> option that enables safe concurrent access.</p>

<p>Previous versions of this documentation suggested using <code>memory =&gt; 0</code> for safe concurrent access. This was mistaken. Tie::File will not support safe concurrent access before version 0.96.</p>

<h1 id="CAVEATS"><a class="permalink" href="./Tie::File.html#CAVEATS">#</a>CAVEATS</h1>

<p>(That&#39;s Latin for &#39;warnings&#39;.)</p>

<ul>

<li><p>Reasonable effort was made to make this module efficient. Nevertheless, changing the size of a record in the middle of a large file will always be fairly slow, because everything after the new record must be moved.</p>

</li>
<li><p>The behavior of tied arrays is not precisely the same as for regular arrays. For example:</p>

<pre><code># This DOES print &quot;How unusual!&quot;
undef $a[10];  print &quot;How unusual!\n&quot; if defined $a[10];</code></pre>

<p><code>undef</code>-ing a <code>Tie::File</code> array element just blanks out the corresponding record in the file. When you read it back again, you&#39;ll get the empty string, so the supposedly-<code>undef</code>&#39;ed value will be defined. Similarly, if you have <code>autochomp</code> disabled, then</p>

<pre><code>	# This DOES print &quot;How unusual!&quot; if &#39;autochomp&#39; is disabled
	undef $a[10];
        print &quot;How unusual!\n&quot; if $a[10];</code></pre>

<p>Because when <code>autochomp</code> is disabled, <code>$a[10]</code> will read back as <code>&quot;\n&quot;</code> (or whatever the record separator string is.)</p>

<p>There are other minor differences, particularly regarding <code>exists</code> and <code>delete</code>, but in general, the correspondence is extremely close.</p>

</li>
<li><p>I have supposed that since this module is concerned with file I/O, almost all normal use of it will be heavily I/O bound. This means that the time to maintain complicated data structures inside the module will be dominated by the time to actually perform the I/O. When there was an opportunity to spend CPU time to avoid doing I/O, I usually tried to take it.</p>

</li>
<li><p>You might be tempted to think that deferred writing is like transactions, with <code>flush</code> as <code>commit</code> and <code>discard</code> as <code>rollback</code>, but it isn&#39;t, so don&#39;t.</p>

</li>
<li><p>There is a large memory overhead for each record offset and for each cache entry: about 310 bytes per cached data record, and about 21 bytes per offset table entry.</p>

<p>The per-record overhead will limit the maximum number of records you can access per file. Note that <i>accessing</i> the length of the array via <code>$x = scalar @tied_file</code> accesses <b>all</b> records and stores their offsets. The same for <code>foreach (@tied_file)</code>, even if you exit the loop early.</p>

</li>
</ul>

<h1 id="SUBCLASSING"><a class="permalink" href="./Tie::File.html#SUBCLASSING">#</a>SUBCLASSING</h1>

<p>This version promises absolutely nothing about the internals, which may change without notice. A future version of the module will have a well-defined and stable subclassing API.</p>

<h1 id="WHAT-ABOUT-DB_File?"><a class="permalink" href="./Tie::File.html#WHAT-ABOUT-DB_File?">#</a><a id="WHAT"></a><a id="WHAT-ABOUT-DB_File"></a>WHAT ABOUT <code>DB_File</code>?</h1>

<p>People sometimes point out that <a href="DB_File.html">DB_File</a> will do something similar, and ask why <code>Tie::File</code> module is necessary.</p>

<p>There are a number of reasons that you might prefer <code>Tie::File</code>. A list is available at <code><a href="http://perl.plover.com/TieFile/why-not-DB_File">http://perl.plover.com/TieFile/why-not-DB_File</a></code>.</p>

<h1 id="AUTHOR"><a class="permalink" href="./Tie::File.html#AUTHOR">#</a>AUTHOR</h1>

<p>Mark Jason Dominus</p>

<p>To contact the author, send email to: <code>mjd-perl-tiefile+@plover.com</code></p>

<p>To receive an announcement whenever a new version of this module is released, send a blank email message to <code>mjd-perl-tiefile-subscribe@plover.com</code>.</p>

<p>The most recent version of this module, including documentation and any news of importance, will be available at</p>

<pre><code class="plaintext">http://perl.plover.com/TieFile/</code></pre>

<h1 id="LICENSE"><a class="permalink" href="./Tie::File.html#LICENSE">#</a>LICENSE</h1>

<p><code>Tie::File</code> version 0.96 is copyright (C) 2003 Mark Jason Dominus.</p>

<p>This library is free software; you may redistribute it and/or modify it under the same terms as Perl itself.</p>

<p>These terms are your choice of any of (1) the Perl Artistic Licence, or (2) version 2 of the GNU General Public License as published by the Free Software Foundation, or (3) any later version of the GNU General Public License.</p>

<p>This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.</p>

<p>You should have received a copy of the GNU General Public License along with this library program; it should be in the file <code>COPYING</code>. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA</p>

<p>For licensing inquiries, contact the author at:</p>

<pre><code class="plaintext">Mark Jason Dominus
255 S. Warnock St.
Philadelphia, PA 19107</code></pre>

<h1 id="WARRANTY"><a class="permalink" href="./Tie::File.html#WARRANTY">#</a>WARRANTY</h1>

<p><code>Tie::File</code> version 0.98 comes with ABSOLUTELY NO WARRANTY. For details, see the license.</p>

<h1 id="THANKS"><a class="permalink" href="./Tie::File.html#THANKS">#</a>THANKS</h1>

<p>Gigantic thanks to Jarkko Hietaniemi, for agreeing to put this in the core when I hadn&#39;t written it yet, and for generally being helpful, supportive, and competent. (Usually the rule is &quot;choose any one.&quot;) Also big thanks to Abhijit Menon-Sen for all of the same things.</p>

<p>Special thanks to Craig Berry and Peter Prymmer (for VMS portability help), Randy Kobes (for Win32 portability help), Clinton Pierce and Autrijus Tang (for heroic eleventh-hour Win32 testing above and beyond the call of duty), Michael G Schwern (for testing advice), and the rest of the CPAN testers (for testing generally).</p>

<p>Special thanks to Tels for suggesting several speed and memory optimizations.</p>

<p>Additional thanks to: Edward Avis / Mattia Barbon / Tom Christiansen / Gerrit Haase / Gurusamy Sarathy / Jarkko Hietaniemi (again) / Nikola Knezevic / John Kominetz / Nick Ing-Simmons / Tassilo von Parseval / H. Dieter Pearcey / Slaven Rezic / Eric Roode / Peter Scott / Peter Somu / Autrijus Tang (again) / Tels (again) / Juerd Waalboer / Todd Rinaldo</p>

<h1 id="TODO"><a class="permalink" href="./Tie::File.html#TODO">#</a>TODO</h1>

<p>More tests. (Stuff I didn&#39;t think of yet.)</p>

<p>Paragraph mode?</p>

<p>Fixed-length mode. Leave-blanks mode.</p>

<p>Maybe an autolocking mode?</p>

<p>For many common uses of the module, the read cache is a liability. For example, a program that inserts a single record, or that scans the file once, will have a cache hit rate of zero. This suggests a major optimization: The cache should be initially disabled. Here&#39;s a hybrid approach: Initially, the cache is disabled, but the cache code maintains statistics about how high the hit rate would be *if* it were enabled. When it sees the hit rate get high enough, it enables itself. The STAT comments in this code are the beginning of an implementation of this.</p>

<p>Record locking with fcntl()? Then the module might support an undo log and get real transactions. What a tour de force that would be.</p>

<p>Keeping track of the highest cached record. This would allow reads-in-a-row to skip the cache lookup faster (if reading from 1..N with empty cache at start, the last cached value will be always N-1).</p>

<p>More tests.</p>


      </div>
      <div id="footer">
        <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p>

<p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p>


      </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
    <script src="../highlight.pack.js"></script>
    <script>hljs.highlightAll();</script>
  </body>
</html>
